package com.ruoyi.generator.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.GeneratedRecords;
import com.ruoyi.generator.service.IGeneratedRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代码生产记录Controller
 * 
 * @author ruoyi
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/generator/records")
public class GeneratedRecordsController extends BaseController
{
    @Autowired
    private IGeneratedRecordsService generatedRecordsService;

//    /**
//     * 列表
//     */
//    @ResponseBody
//    @RequestMapping("/genlist")
//    public AjaxResult genlist(GeneratedRecords generatedRecords){
//        List<Map<String, Object>> list=generatedRecordsService.queryList(generatedRecords);
//        return new AjaxResult("page", pageUtil);
//    }
//
//    /**
//     * 生成代码
//     */
//    @RequestMapping("/code")
//    public void code(String tables, HttpServletResponse response) throws IOException {
//        byte[] data = sysGeneratorService.generatorCode(tables.split(","));
//
//        response.reset();
//        response.setHeader("Content-Disposition", "attachment; filename=\"lanj.zip\"");
//        response.addHeader("Content-Length", "" + data.length);
//        response.setContentType("application/octet-stream; charset=UTF-8");
//        IOUtils.write(data, response.getOutputStream());
//    }

    /**
     * 查询代码生产记录列表
     */
    @PreAuthorize("@ss.hasPermi('generator:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(GeneratedRecords generatedRecords)
    {
        startPage();
        List<GeneratedRecords> list = generatedRecordsService.selectGeneratedRecordsList(generatedRecords);
        return getDataTable(list);
    }

    /**
     * 导出代码生产记录列表
     */
    @PreAuthorize("@ss.hasPermi('generator:records:export')")
    @Log(title = "代码生产记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GeneratedRecords generatedRecords)
    {
        List<GeneratedRecords> list = generatedRecordsService.selectGeneratedRecordsList(generatedRecords);
        ExcelUtil<GeneratedRecords> util = new ExcelUtil<GeneratedRecords>(GeneratedRecords.class);
        util.exportExcel(response, list, "代码生产记录数据");
    }

    /**
     * 获取代码生产记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('generator:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(generatedRecordsService.selectGeneratedRecordsById(id));
    }

    /**
     * 新增代码生产记录
     */
    @PreAuthorize("@ss.hasPermi('generator:records:add')")
    @Log(title = "代码生产记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GeneratedRecords generatedRecords)
    {
        return toAjax(generatedRecordsService.insertGeneratedRecords(generatedRecords));
    }

    /**
     * 修改代码生产记录
     */
    @PreAuthorize("@ss.hasPermi('generator:records:edit')")
    @Log(title = "代码生产记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GeneratedRecords generatedRecords)
    {
        return toAjax(generatedRecordsService.updateGeneratedRecords(generatedRecords));
    }

    /**
     * 删除代码生产记录
     */
    @PreAuthorize("@ss.hasPermi('generator:records:remove')")
    @Log(title = "代码生产记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(generatedRecordsService.deleteGeneratedRecordsByIds(ids));
    }
}
